home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / win / wpause.c < prev    next >
C/C++ Source or Header  |  1993-09-15  |  8KB  |  265 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: wpause.c%v 3.50 1993/07/09 05:35:24 woo Exp $";
  3. #endif
  4.  
  5. /* GNUPLOT - win/wpause.c */
  6. /*
  7.  * Copyright (C) 1992   Russell Lang
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software is provided "as is" without express or implied warranty.
  20.  * 
  21.  *
  22.  * AUTHORS
  23.  * 
  24.  *   Russell Lang
  25.  * 
  26.  * Send your comments or suggestions to 
  27.  *  info-gnuplot@dartmouth.edu.
  28.  * This is a mailing list; to join it send a note to 
  29.  *  info-gnuplot-request@dartmouth.edu.  
  30.  * Send bug reports to
  31.  *  bug-gnuplot@dartmouth.edu.
  32.  */
  33. /* PauseBox() */
  34.  
  35. /* MessageBox ALWAYS appears in the middle of the screen so instead */
  36. /* we use this PauseBox so we can decide where it is to be placed */
  37.  
  38. #define STRICT
  39. #include <windows.h>
  40. #include <windowsx.h>
  41. #include <string.h>
  42. #include "wgnuplib.h"
  43. #include "wresourc.h"
  44. #include "wcommon.h"
  45.  
  46. /* Pause Window */
  47. LRESULT CALLBACK _export WndPauseProc(HWND, UINT, WPARAM, LPARAM);
  48. LRESULT CALLBACK _export PauseButtonProc(HWND, UINT, WPARAM, LPARAM);
  49.  
  50. /* Create Pause Class */
  51. /* called from PauseBox the first time a pause window is created */
  52. void
  53. CreatePauseClass(LPPW lppw)
  54. {
  55.     WNDCLASS wndclass;
  56.  
  57.     wndclass.style = 0;
  58.     wndclass.lpfnWndProc = (WNDPROC)WndPauseProc;
  59.     wndclass.cbClsExtra = 0;
  60.     wndclass.cbWndExtra = sizeof(void FAR *);
  61.     wndclass.hInstance = lppw->hInstance;
  62.     wndclass.hIcon = NULL;
  63.     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  64.     wndclass.hbrBackground = GetStockBrush(WHITE_BRUSH);
  65.     wndclass.lpszMenuName = NULL;
  66.     wndclass.lpszClassName = szPauseClass;
  67.     RegisterClass(&wndclass);
  68. }
  69.  
  70. /* PauseBox */
  71. int WDPROC
  72. PauseBox(LPPW lppw)
  73. {
  74.     MSG msg;
  75.     HDC hdc;
  76.     int width, height;
  77.     TEXTMETRIC tm;
  78.     RECT rect;
  79.  
  80.     if (!lppw->hPrevInstance)
  81.         CreatePauseClass(lppw);
  82.     GetWindowRect(GetDesktopWindow(), &rect);
  83.     if ( (lppw->Origin.x == CW_USEDEFAULT) || (lppw->Origin.x == 0) )
  84.         lppw->Origin.x = (rect.right + rect.left) / 2;
  85.     if ( (lppw->Origin.y == CW_USEDEFAULT) || (lppw->Origin.y == 0) )
  86.         lppw->Origin.y = (rect.bottom + rect.top) / 2;
  87.  
  88.     hdc = GetDC(NULL);
  89.     SelectFont(hdc, GetStockFont(SYSTEM_FIXED_FONT));
  90.     GetTextMetrics(hdc, &tm);
  91.     width  = max(24,4+_fstrlen(lppw->Message)) * tm.tmAveCharWidth;
  92.     width = min(width, rect.right-rect.left);
  93.     height = 28 * (tm.tmHeight + tm.tmExternalLeading) / 4;
  94.     ReleaseDC(NULL,hdc);
  95.  
  96.     lppw->lpfnPauseButtonProc = 
  97. #ifdef __DLL__
  98.         (WNDPROC)GetProcAddress(hdllInstance, "PauseButtonProc");
  99. #else
  100.         (WNDPROC)MakeProcInstance((FARPROC)PauseButtonProc ,hdllInstance);
  101. #endif
  102.     lppw->hWndPause = CreateWindowEx(WS_EX_DLGMODALFRAME, 
  103.         szPauseClass, lppw->Title,
  104.         WS_POPUPWINDOW | WS_CAPTION,
  105.         lppw->Origin.x - width/2, lppw->Origin.y - height/2,
  106.         width, height,
  107.         lppw->hWndParent, NULL, lppw->hInstance, lppw);
  108.     ShowWindow(lppw->hWndPause, SW_SHOWNORMAL);
  109.     BringWindowToTop(lppw->hWndPause);
  110.     UpdateWindow(lppw->hWndPause);
  111.  
  112.     lppw->bPause = TRUE;
  113.     lppw->bPauseCancel = IDCANCEL;
  114.     while (lppw->bPause)
  115.             while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  116.             /* wait until window closed */
  117.                 TranslateMessage(&msg);
  118.                 DispatchMessage(&msg);
  119.             }
  120.     DestroyWindow(lppw->hWndPause);
  121. #ifndef __DLL__
  122.     FreeProcInstance((FARPROC)lppw->lpfnPauseButtonProc);
  123. #endif
  124.  
  125.     return(lppw->bPauseCancel);
  126. }
  127.  
  128. LRESULT CALLBACK _export
  129. WndPauseProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  130. {
  131.     HDC hdc;
  132.     PAINTSTRUCT ps;
  133.     RECT rect;
  134.     TEXTMETRIC tm;
  135.     LPPW lppw;
  136.     int cxChar, cyChar, middle;
  137.  
  138.     lppw = (LPPW)GetWindowLong(hwnd, 0);
  139.  
  140.     switch(message) {
  141.         case WM_KEYDOWN:
  142.             if (wParam == VK_RETURN) {
  143.                 if (lppw->bDefOK)
  144.                     SendMessage(hwnd, WM_COMMAND, IDOK, 0L);
  145.                 else
  146.                     SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
  147.             }
  148.             return(0);
  149.         case WM_COMMAND:
  150.             switch(LOWORD(wParam)) {
  151.                 case IDCANCEL:
  152.                 case IDOK:
  153.                     lppw->bPauseCancel = LOWORD(wParam);
  154.                     lppw->bPause = FALSE;
  155.                     break;
  156.             }
  157.             return(0);
  158.         case WM_SETFOCUS:
  159.             SetFocus(lppw->bDefOK ? lppw->hOK : lppw->hCancel);
  160.             return(0);
  161.         case WM_PAINT:
  162.             {
  163.             hdc = BeginPaint(hwnd, &ps);
  164.             SelectFont(hdc, GetStockFont(SYSTEM_FIXED_FONT));
  165.             SetTextAlign(hdc, TA_CENTER);
  166.             GetClientRect(hwnd, &rect);
  167.             TextOut(hdc,(rect.right+rect.left)/2, (rect.bottom+rect.top)/6,
  168.                 lppw->Message,_fstrlen(lppw->Message));
  169.             EndPaint(hwnd, &ps);
  170.             return 0;
  171.             }
  172.         case WM_CREATE:
  173.             {
  174.             HMENU sysmenu = GetSystemMenu(hwnd, FALSE);
  175.             lppw = ((CREATESTRUCT FAR *)lParam)->lpCreateParams;
  176.             SetWindowLong(hwnd, 0, (LONG)lppw);
  177.             lppw->hWndPause = hwnd;
  178.             hdc = GetDC(hwnd);
  179.             SelectFont(hdc, GetStockFont(SYSTEM_FIXED_FONT));
  180.             GetTextMetrics(hdc, &tm);
  181.             cxChar = tm.tmAveCharWidth;
  182.             cyChar = tm.tmHeight + tm.tmExternalLeading;
  183.             ReleaseDC(hwnd,hdc);
  184.             middle = ((LPCREATESTRUCT) lParam)->cx / 2;
  185.             lppw->hOK = CreateWindow((LPSTR)"button", (LPSTR)"OK",
  186.                 WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
  187.                     middle - 10*cxChar, 3*cyChar,
  188.                     8*cxChar, 7*cyChar/4,
  189.                     hwnd, (HMENU)IDOK,
  190.                     ((LPCREATESTRUCT) lParam)->hInstance, NULL);
  191.             lppw->bDefOK = TRUE;
  192.             lppw->hCancel = CreateWindow((LPSTR)"button", (LPSTR)"Cancel",
  193.                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  194.                     middle + 2*cxChar, 3*cyChar,
  195.                     8*cxChar, 7*cyChar/4,
  196.                     hwnd, (HMENU)IDCANCEL,
  197.                     ((LPCREATESTRUCT) lParam)->hInstance, NULL);
  198.             lppw->lpfnOK = (WNDPROC) GetWindowLong(lppw->hOK, GWL_WNDPROC);
  199.             SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
  200.             lppw->lpfnCancel = (WNDPROC) GetWindowLong(lppw->hCancel, GWL_WNDPROC);
  201.             SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
  202.             if (GetParent(hwnd))
  203.                 EnableWindow(GetParent(hwnd),FALSE);
  204.             DeleteMenu(sysmenu,SC_RESTORE,MF_BYCOMMAND);
  205.             DeleteMenu(sysmenu,SC_SIZE,MF_BYCOMMAND);
  206.             DeleteMenu(sysmenu,SC_MINIMIZE,MF_BYCOMMAND);
  207.             DeleteMenu(sysmenu,SC_MAXIMIZE,MF_BYCOMMAND);
  208.             DeleteMenu(sysmenu,SC_TASKLIST,MF_BYCOMMAND);
  209.             DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
  210.             DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
  211.             }
  212.             return 0;
  213.         case WM_DESTROY:
  214.             GetWindowRect(hwnd, &rect);
  215.             lppw->Origin.x = (rect.right+rect.left)/2;
  216.             lppw->Origin.y = (rect.bottom+rect.top)/2;
  217.             lppw->bPause = FALSE;
  218.             if (GetParent(hwnd))
  219.                 EnableWindow(GetParent(hwnd),TRUE);
  220.             break;
  221.     }
  222.     return DefWindowProc(hwnd, message, wParam, lParam);
  223. }
  224.  
  225.  
  226. LRESULT CALLBACK _export
  227. PauseButtonProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  228. {
  229.     LPPW lppw;
  230. #ifdef WIN32
  231.     LONG n = GetWindowLong(hwnd, GWL_ID);
  232. #else
  233.     WORD n = GetWindowWord(hwnd, GWW_ID);
  234. #endif
  235.     lppw = (LPPW)GetWindowLong(GetParent(hwnd), 0);
  236.     switch(message) {
  237.         case WM_KEYDOWN:
  238.             switch(wParam) {
  239.               case VK_TAB:
  240.               case VK_BACK:
  241.               case VK_LEFT:
  242.               case VK_RIGHT:
  243.               case VK_UP:
  244.               case VK_DOWN:
  245.                 lppw->bDefOK = !(n == IDOK);
  246.                 if (lppw->bDefOK) {
  247.                     SendMessage(lppw->hOK,     BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)TRUE);
  248.                     SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, (LPARAM)TRUE);
  249.                     SetFocus(lppw->hOK);
  250.                 }
  251.                 else {
  252.                     SendMessage(lppw->hOK,     BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, (LPARAM)TRUE);
  253.                     SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)TRUE);
  254.                     SetFocus(lppw->hCancel);
  255.                 }
  256.                 break;
  257.               default:
  258.                 SendMessage(GetParent(hwnd), message, wParam, lParam);
  259.             }
  260.             break;
  261.     }
  262.     return CallWindowProc(((n == IDOK) ? lppw->lpfnOK : lppw->lpfnCancel),
  263.          hwnd, message, wParam, lParam);
  264. }
  265.